﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace Odebrecht.WpfControls
{
    public class CustomDataGridRow : DataGridRow
    {
        #region Constructors

        public CustomDataGridRow()
        {
            this.Loaded += OnLoaded;
        }

        #endregion Constructors

        #region Methods

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var border = GetTemplateChild("DGR_Border") as Border;
            var scroll = border.Child as SelectiveScrollingGrid;
            var uiElementCollection = scroll.Children as UIElementCollection;
            var dataGridCellsPresenter = uiElementCollection[0] as DataGridCellsPresenter;

            dataGridCellsPresenter.SetBinding(DataGridCellsPresenter.HeightProperty, new Binding("RowHeight") { Source = this.Item, Mode = BindingMode.TwoWay });
        }

        #endregion Methods
    }
}